<?php
class CMS_Core {


    public static function start()
    {
        Zend_Session::start();

        Zend_Layout::startMvc();

        $conf = CMS_Config::getInstance(CMS_INSTANCE_SERVER);

        if($conf->debug->mode)
        	Common_Log::enable(true);
        else
        	Common_Log::enable(false);

        $db = CMS_Db::connect($conf->database->adapter, $conf->database->host, $conf->database->username, $conf->database->password, $conf->database->dbname);
       // $db = Zend_DB::factory($config->dbname);
		Zend_DB_Table_Abstract::setDefaultAdapter($db);  
		$front = Zend_Controller_Front::getInstance();
        $front->addModuleDirectory(SYSTEM_PATH.'/application/modules/');
        $routeHome = new Zend_Controller_Router_Route_Regex('([a-z]{2})',
                                                            array("controller" => 'index', 'action' => 'index') ,
                                                            array( 1 => 'lang' ) );
        
        $routeContenidos = new Zend_Controller_Router_Route_Regex('([a-z]{2})/([A-Z|a-z|\-|_]+)/([0-9]+)\.html',
												    array( 'controller' => 'content', 'action' => 'index' ),
												    array ( 1 => 'lang', 2 => 'title', 3 => "id" )
												);
		$routeContacto = new Zend_Controller_Router_Route_Regex("contact", array( 'controller' => 'contact' , 'action' => 'index'));

		
		$routeAdmin = new Zend_Controller_Router_Route_Static("admin", array( 'module' => 'admin' , 'controller' => 'user' , 'action' => 'login' ));
		$router = new Zend_Controller_Router_Rewrite();
		//$router->removeDefaultRoutes();
		$router->addRoute('home', $routeHome);
     	$router->addRoute('contenidos',$routeContenidos);
     	$router->addRoute('contacto',$routeContacto);
     	$router->addRoute('admin',$routeAdmin);
     	$front->setRouter($router);
        $front->throwExceptions(false);
        $front->dispatch();
    }
    
    
    public static function noMVC()
    {
       Zend_Session::start();

        $conf = CMS_Config::getInstance(CMS_INSTANCE_SERVER);

        if($conf->debug->mode)
        	Common_Log::enable(true);
        else
        	Common_Log::enable(false);

        $db = CMS_Db::connect($conf->database->adapter, $conf->database->host, $conf->database->username, $conf->database->password, $conf->database->dbname);
       // $db = Zend_DB::factory($config->dbname);
		Zend_DB_Table_Abstract::setDefaultAdapter($db);  
        	

        try
        {
            $locale = new Zend_Locale(Zend_Locale::BROWSER);
        }
        catch(Exception $e)
        {
            $locale = "es";
        }
        Zend_Registry::set('Zend_Locale', $locale);


    }    
}
?>
